import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 拓展记录信息 */
export interface ExpandRecord {
  id: number // ID
  interviewee: string // 受访人
  intervieweePhone: string // 受访人电话
  intervieweePosition: string // 受访人职位
  customerRequire: string // 客户需求
  breakthroughPoint: string // 切入点
  expandTime: string | Dayjs // 拓展时间
  businessType: string // 业务类型
  expandProcess: string // 拓展进度
  expandSituation: string // 拓展情况
  customerType: string // 客户类型
  customerLevel: string // 客户级别
  nextTimeVisit: string | Dayjs // 下次拜访时间
  scenePictureUrl: string // 现场图片url
  securityReportUrl: string // 安全评测报告url
  serviceSchemeUrl: string // 安全方案url
  ownerUserId: number // 拓展所属人id
}

// 拓展记录 API
export const ExpandRecordApi = {
  // 查询拓展记录分页
  getExpandRecordPage: async (params: any) => {
    return await request.get({ url: `/san/biz-expand-record/page`, params })
  },

  // 查询拓展记录详情
  getExpandRecord: async (id: number) => {
    return await request.get({ url: `/san/biz-expand-record/get?id=` + id })
  },

  // 新增拓展记录
  createExpandRecord: async (data: ExpandRecord) => {
    return await request.post({ url: `/san/biz-expand-record/create`, data })
  },

  // 修改拓展记录
  updateExpandRecord: async (data: ExpandRecord) => {
    return await request.put({ url: `/san/biz-expand-record/update`, data })
  },

  // 删除拓展记录
  deleteExpandRecord: async (id: number) => {
    return await request.delete({ url: `/san/biz-expand-record/delete?id=` + id })
  },

  /** 批量删除拓展记录 */
  deleteExpandRecordList: async (ids: number[]) => {
    return await request.delete({ url: `/san/biz-expand-record/delete-list?ids=${ids.join(',')}` })
  },

  // 导出拓展记录 Excel
  exportExpandRecord: async (params) => {
    return await request.download({ url: `/san/biz-expand-record/export-excel`, params })
  },

  // 查询拓展记录详情
  getCountByType: async (type: number) => {
    return await request.get({ url: `/san/biz-expand-record/countByType?type=` + type })
  },
  // 获取所有拓展人的拓展统计
  countAllUserExpand: async (params) => {
    return await request.post({ url: `/san/biz-expand-record/countAllUserExpand`, params })
  },
  // 查询列表中重复名字的最新一条数据列表并获取数量
  getExpandRecordCurrent: async (params) => {
    return await request.post({ url: `/san/biz-expand-record/getExpandRecordCurrent`, params })
  },
  // 查询当前租户的合同金额和签约数量
  getExpandRecordGk: async (id: any) => {
    return await request.get({ url: `/san/biz-expand-record/getExpandRecordGk` })
  },
  getListByCondition: async (params: any) => {
    return await request.get({ url: `/san/biz-expand-record/getListByCondition`, params })
  },
  getListByInterviewee: async (params: any) => {
    return await request.get({ url: `/san/biz-expand-record/getListByInterviewee`, params })
  },
  checkRecordByCustomerName: async (customerName: string) => {
    return await request.get({
      url: `/san/biz-expand-record/checkRecordByCustomerName?customerName=` + customerName
    })
  }
}

export const ExpandProcessOptionsGroup = [
  {
    label: '前期沟通',
    options: [
      { label: '初步沟通', value: '01_01' },
      { label: '安全评测', value: '01_02' },
      { label: '评测报告讲解', value: '01_03' },
      { label: '服务方案讲解', value: '01_04' },
      { label: '方案讲解后持续沟通', value: '01_05' }
    ]
  },
  {
    label: '商业谈判',
    options: [
      { label: '价格谈判', value: '02_01' },
      { label: '合同条款谈判', value: '02_02' },
      { label: '签订合同(新签)', value: '02_03' }
    ]
  },
  {
    label: '服务跟进',
    options: [
      { label: '客户关系维护', value: '03_01' },
      { label: '现场交谈', value: '03_02' },
      { label: '收款跟踪', value: '03_03' },
      { label: '续约跟踪', value: '03_04' },
      { label: '续签合同', value: '03_05' }
    ]
  },
  {
    label: '其他',
    options: [
      { label: '终止洽谈(新签)', value: '04_01' },
      { label: '终止洽谈(续签)', value: '04_02' },
      { label: '其他', value: '04_03' }
    ]
  }
]
